{% extends 'layout.html' %}
<!--
继承+重写
-->
{%block main%}
<div class="blog-container">
    <div class="">分类编辑页面</div>
    <div>当前用户：{{userinfo.username}}</div>
    <h3>编辑分类:{{category.name}}（<span id="typeid">{{category._id.toString()}}</span>）</h3>
    <!-- onsubmit="return false" action="#" id="formtest"-->

<!--    <form method="post" id="formtest">-->
<!--        <div>-->
<!--            <label for="name">分类名称</label>-->
<!--            <input type="text" value="{{category.name}}" name="name" placeholder="name" id="name">-->
<!--        </div>-->
<!--        <button type="submit">提交</button>-->
<!--    </form>-->

    <div>
        <label for="name">分类名称</label>
        <input type="text" value="{{category.name}}" name="name" placeholder="name" id="name">
    </div>
<!--    <button type="submit">提交</button>-->
    <button id="tj">提交</button>
</div>
<script>
    // bodyparser插件解析模式有问题，暂时只能用axios去提交请求
    $(document).on('click','#tj',function () {
        const name = document.getElementById('name').value;
        const dd = {
            name: name,
            id:$('#typeid').html()
        };
        // var test = new FormData($('#formtest')[0]);
        console.log(name);
        axios({
            method: 'post',
            url: '/admin/category/edit',
            data: dd
        }).then(function (response) {
            // console.log(response);
            alert(response.data.name);
            window.location.href='http://localhost:8080/'+response.data.url;
            // alert(response);
        });
    });

</script>
{%endblock%}
